
if __name__ == '__main__':
    cat1_file = '../../../../resource/cat_1.csv'
    cat2_file = '../../../../resource/cat_2.csv'
    out_file = '../../../../resource/cat_12.csv'
    cat_12_file = '/Users/hardy/20W_Result/cat_count_tb.txt'
    cat_dict = dict()

    for l in open(cat1_file):
        d = l.strip().split(',')
        if d[2].strip():
            cat_dict[d[1].strip()] = d[2].strip()

    for l in open(cat2_file):
        d = l.strip().split(',')
        if d[2].strip():
            cat_dict[d[1].strip()] = d[2].strip()

    with open(out_file, 'w+') as fd:
        for l in open(cat_12_file):
            cat2 = ''
            d = l.strip().split('\t')
            count, cat1 = d[0].strip().split()
            if len(d) > 1:
                cat2 = d[1]

            yz_cat2 = ''
            if cat_dict.get(cat1):
                yz_cat2 = cat_dict.get(cat1)
            elif cat_dict.get(cat2):
                yz_cat2 = cat_dict.get(cat2)
            else:
                yz_cat2 = ''

            out = '\t'.join([count, cat1, cat2, yz_cat2])
            fd.write(out + '\n')



